#define CHECK printf("CHECK"); getchar();
#include <limits.h>
#include "BFS.h"

inline int log2(int x){
    int count = 0;
    while(x>1){
        count++;
        x >>=1;
    }
    return count;
}


/// FOR DEBUGS
void show(vEBTree<WORDTYPE>*word, int n){
    int i;	
    for( i = 1 ; i < n ; i++){
        if(word->isInSet(i))printf("(%d) ",i);
    }
    printf("Continue ?\n");
    getchar();
}


void bitMapBFS(Digraph *digraph, int root,void f(int )){
   int n = digraph->size;
   int v = root;


   vEBTreeFactory<WORDTYPE>* factory = new ArrayvEBTreeFactory<WORDTYPE>(); 	
   vEBTree<WORDTYPE>** adj = digraph->adj;
   vEBTree<WORDTYPE>* visit = new ArrayvEBTree<WORDTYPE>(factory,n,1);
   visit->allToSet();
   vEBTree<WORDTYPE>* suc = new ArrayvEBTree<WORDTYPE>(factory,n,1);
   vEBTree<WORDTYPE>* queue = new ArrayvEBTree<WORDTYPE>(factory,n,1);
   vEBTree<WORDTYPE>* aux;
   suc->toSet(root);

   while(!suc->isEmpty()){
	aux = queue;
	queue = suc;
	suc = aux;

	printf(" \n queue \n");
	queue->show();

	v = queue->nextSetElement(0);
	printf("novo nível\n");
	while(v < n){
		f(v);
		visit->toCompl(v);
		queue->toCompl(v);
		suc->logicor(adj[v]);
		v = queue->nextSetElement(v);
	}
	printf("\n visit \n");
	visit->show();
	getchar();
	suc->logicand(visit);
	printf("\n succ \n");
	suc->show();
	getchar();
   }
}

















